import axios from '@/libs/axios1'
import qs from 'qs'
let jsonHeaders = { 'content-type': 'application/json;charset=UTF-8' }
let exp = '/self-study/exp'
let myCourse = '/self-study/mycourse'
let range = '/self-study/range'

export const templateAutomatic = (data) => {
    return axios({
        url: `/resource-manager/template/automatic?visibility=company`,
        method: 'post',
        data: data,
        headers: jsonHeaders
    });
};

// 根据关联实物设备，生成镜像的接口啊啊啊
export const templateAutomaticImage = (data) => {
    return axios({
        url: `/topo-edit/tmpl/automatic/template`,
        method: 'post',
        data: data,
        headers: jsonHeaders
    });
};


// 获取课件列表
export const getExpList = params => {
    return axios({
        url: `${exp}/experiment/page`,
        method: 'get',
        params: params,
        headers: jsonHeaders,
        paramsSerializer: function (params) {
            return qs.stringify(params, { arrayFormat: 'repeat' })
        }
    })
}

export const getExpList_new = params => {
    return axios({
        url: `${exp}/experiment/pageExceptVideo`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

// 创建课件
export const submitExper = (data) => {
    return axios({
        url: `${exp}/experiment`,
        method: 'post',
        data: JSON.stringify(data),
        headers: jsonHeaders,
    })
}
// 删除课件
export const delExper = (id) => {
    return axios({
        url: `${exp}/experiment/${id}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
// 修改课件
export const modifyExper = (id, data) => {
    return axios({
        url: `${exp}/experiment/${id}`,
        method: 'put',
        data: JSON.stringify(data),
        headers: jsonHeaders,
    })
}

//获取课件详情
export const experimentDetail = params => {
    return axios({
        url: `${exp}/experiment/${params.eid}`,
        method: 'get',
        headers: jsonHeaders
    })
}

//创建课件试题
export const addExpQuestion = params => {
    return axios({
        url: `${exp}/expQuestion`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    })
}

// 获取课程列表-分页
export const getcourselist = params => {
    return axios({
        url: `${exp}/course/page`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

// 获取课程列表-不分页
export const getallcourselist = params => {
    return axios({
        url: `${exp}/course/list`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}


// 获取课程课件列表
export const courseExpDetail = params => {
    return axios({
        url: `${exp}/course/getExpListById?ccid=` + params,
        method: 'get',
        headers: jsonHeaders
    })
}

//修改课件试题
export const modifyExpQuestion = (ecid, params) => {
    return axios({
        url: `${exp}/expQuestion/${ecid}`,
        method: 'put',
        data: params,
        headers: jsonHeaders
    })
}

//查询课件习题
export const queryExpQuestion = (params) => {
    return axios({
        url: `${exp}/expQuestion/page`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

//删除课件习题
export const delExpQuestion = ecid => {
    return axios({
        url: `${exp}/expQuestion/${ecid}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

//删除课件习题(单个)
export const delExpQuestionS = (ecId, questionId) => {
    return axios({
        url: `${exp}/expQuestion/delExpQuestion/${ecId}?questionId=${questionId}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

// 获取课程详情
export const courseDetail = params => {
    return axios({
        url: `${exp}/course/${params}`,
        method: 'get',
        headers: jsonHeaders
    })
}

// 删除课程
export const delCourse = params => {
    return axios({
        url: `${exp}/course/${params.ccId}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

// 添加课程
export const addCourse = params => {
    return axios({
        url: `${exp}/course`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    })
}

// 修改课程
export const updateCourse = (id, obj) => {
    return axios({
        url: `${exp}/course/${id}`,
        method: 'put',
        data: obj,
        headers: jsonHeaders
    })
}


//启用或禁用课程
export const changeCourseEnable = (params) => {
    return axios({
        url: `${exp}/course/batchEnable`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    })
}



//评论
export const delComment = id => {
    return axios({
        url: `${exp}/comments/${id}`,
        method: 'delete',
        headers: jsonHeaders
    })
}
export const getCommentList = params => {
    return axios({
        url: `${exp}/comments`,
        method: 'get',
        params,
        headers: jsonHeaders
    })
}
//课件课程笔记
export const delNotes = id => {
    return axios({
        url: `${exp}/learnNotes/${id}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

//获取笔记列表
export const getNotesList = params => {
    return axios({
        url: `${exp}/learnNotes`,
        method: 'get',
        params,
        headers: jsonHeaders
    })
}

//获取答题详情
export const getExpQuestionAnswerDetail = (ecid, params) => {
    return axios({
        url: `${exp}/expQuestion/getExpQuestionByUserId/${ecid}`,
        method: 'GET',
        params: params,
        headers: jsonHeaders
    })
}

//获取答题详情-新-指导书答题
export const getGuideQuestionAnswerDetail = (ecid, params) => {
    return axios({
        url: `/self-study/guide/expQuestion/getExpGuideQuestionByUserId/${ecid}`,
        method: 'GET',
        params: params,
        headers: jsonHeaders
    })
}

//获取课件部署详情
export const expEnv = (path, params) => {
    return axios({
        url: `${myCourse}/myExp/expEnv/${path.uid}/${path.eid}`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

//获取课程订阅者
export const getCourseSubscriber = (params) => {
    return axios({
        url: `${myCourse}/list`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

//获取课件订阅者
export const getExperSubscriber = (params) => {
    return axios({
        url: `${myCourse}/myExp/list`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

//获取课件订阅者的分页数据
export const getExperSubscriberPage = (params) => {
    return axios({
        url: `${myCourse}/myExp/page`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

//销毁课件部署
export const experimentDestroy = params => {
    return axios({
        url: `${range}/expMachine/destroy/` + params.projectId + `/` + params.userId,
        method: 'delete',
        headers: jsonHeaders
    })
}

//获取视频详情
export const getVideoDetail = (ecId, params) => {
    return axios({
        url: `${range}/expVideoRes/queryExpAllVideos/${ecId}`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

//获取虚拟机列表
export const getVms = params => {
    return axios({
        url: `${range}/expMachine/queryVms/${params}`,
        method: 'get',
        headers: jsonHeaders
    })
}

// 轮询课件状态
export const queryInterval = (id) => {
    return axios({
        url: `${range}/expMachine/progress/${id}`,
        method: 'get',
        headers: jsonHeaders,
    })
}
// 销毁课件
export const destroyExper = (projectId, userid) => {
    return axios({
        url: `${range}/expMachine/destroy/${projectId}/${userid}`,
        method: 'delete',
        headers: jsonHeaders,
    })
}
// 创建课件机
export const creatExper = (data) => {
    return axios({
        url: `${range}/expMachine/create`,
        method: 'post',
        data: JSON.stringify(data),
        headers: jsonHeaders,
    })
}


//清空课件视频和课件
export const clearExpVideo = ecId => {
    return axios({
        url: `${range}/expVideoRes/deleteAll/${ecId}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

//获取自动销毁时间毫秒
export const getTime = params => {
    return axios({
        url: `${range}/expMachine/selectTime/${params}`,
        method: 'get',
        headers: jsonHeaders
    })
}


//添加课件视频
export const addExpVideo = params => {
    return axios({
        url: `${range}/expVideoRes/add`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    })
}

//删除课件视频
export const delExpVideo = srcId => {
    return axios({
        url: `${range}/expVideoRes/delete/${srcId}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

//修改课件视频
export const modifyExpVideo = (srcId, params) => {
    return axios({
        url: `${range}/expVideoRes/update/${srcId}`,
        method: 'put',
        data: params,
        headers: jsonHeaders
    })
}

export const geturl = params => {
    return axios({
        url: `/netns/access/${params.vmId}/${params.type}`,
        method: 'post',
        data: params.data,
        headers: jsonHeaders
    })
}

//查询工程部署详情
export const getProjectDeployDetail = (deployId, params) => {
    return axios({
        url: `/deploy/deploying/${deployId}/detail`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}
//获取锚点笔记列表
export const queryAchorNote = (params) => {
    return axios({
        url: `${exp}/learnNotes/anchorPages`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    })
}

export const addOrUpdateChapter = (params) => {
    return axios({
        url: `${myCourse}/myExp/addOrUpdateChapter`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    })
}
export const getChapter = (id) => {
    return axios({
        url: `${myCourse}/myExp/getChapter?ccId=${id}`,
        method: 'get',
        headers: jsonHeaders
    })
}

// 查询课件状态
export const experStatus = (userid, ecid) => {
    return axios({
        url: `${myCourse}/myExp/expEnv/${userid}/${ecid}`,
        method: 'get',
        headers: jsonHeaders
    });
};

//查询替换镜像记录列表
export const getCreateImageList = (params) => {
    return axios({
        url: `/quickexp/replaceImage/page`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    });
};


//替换模板记录
export const getRepTemplateList = (params) => {
    return axios({
        url: `/quickexp/replaceTempl/page`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    });
};

//执行替换镜像并生成模板
export const repAndCreateTemplate = (params) => {
    return axios({
        url: `/quickexp/replaceImage/repAndCreate/`,
        method: 'post',
        data: params,
        headers: jsonHeaders
    });
};
//获取工程详情-状态
export const getProjectInfo = (projectId) => {
    return axios({
        url: `/topo-edit/project/${projectId}`,
        method: 'get',
        params: {},
        headers: jsonHeaders
    });
};

export const clearDeloyPro = (id, data) => {
    return axios({
        url: `/topo-edit/project/clear/${id}`,
        method: 'post',
        data: JSON.stringify(data),
        headers: jsonHeaders
    });
};
//获取自动销毁时间毫秒
export const getDestroyTime = (params) => {
    return axios({
        url: `${range}/expMachine/selectTime/${params}`,
        method: 'get',
        headers: jsonHeaders
    });
};

//延长试验销毁时间
export const extendDestroyTime = (projectId) => {
    return axios({
        url: `${range}/expMachine/extend/${projectId}`,
        method: 'post',
        params: {},
        headers: jsonHeaders
    });
};

// 轮询课件状态
export const queryExpDeployProgress = (id) => {
    return axios({
        url: `${range}/expMachine/progress/${id}`,
        method: 'get',
        headers: jsonHeaders
    });
};
//删除替换镜像记录
export const delCreateImage = (data) => {
    return axios({
        url: `/quickexp/replaceImage/del`,
        method: 'delete',
        data: data,
        headers: jsonHeaders
    });
};
export const getExpListNotPrivate = (params) => {
    return axios({
        url: `${exp}/experiment/managerPage`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    });
};
//查询课件习题 -- 含详情
export const queryExpQuestionDetail = (params) => {
    return axios({
        url: `${exp}/expQuestion/pageDetailByEcid`,
        method: 'get',
        params: params,
        headers: jsonHeaders
    });
};

//一键设置所有的课件（自学，非自学）
export const setAllExpSelfType = (params) => {
    return axios({
        url: `${exp}/experiment/setExperimentSelfType`,
        method: 'POST',
        params: params,
        headers: jsonHeaders,
        paramsSerializer: (params) => {
            return qs.stringify(params, { indices: false });
        }
    });
};

// 查询当前平均分
export const getScoreAvg = params => {
    return axios({
        url: `${exp}/comments/starAvg`,
        method: 'get',
        params,
        headers: jsonHeaders
    })
}


// 获取实物设备类型
// http://172.172.10.178/api/resource-manager/sysDict/data/list?dictType=custom_device&pageIndex=1&pageSize=100000
export const getDeviceType = params => {
    return axios({
        url: `/resource-manager/sysDict/data/list?dictType=custom_device&pageIndex=1&pageSize=100000`,
        method: 'get',
        params: params,
        headers: jsonHeaders,
    })
}